<?php 
/*
$JA#COPYRIGHT$
*/

// No direct access

defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.model' );
JHTML::_('behavior.tooltip');

// Check component installed
if( ! file_exists(JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'asset'.DS.'jaconstants.php') ){
	echo "JAJobBoard must be install first before using this module.";
	return ;
}

require_once JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'asset'.DS.'jaconstants.php';
require_once JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'asset'.DS.'japermissions.php';
require_once(JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'helper'.DS.'jafunctions.class.php');
require_once JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'asset'.DS.'rendfield.php';
require_once(JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'helper'.DS.'jahelper.php');
require_once(JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'models'.DS.'jajobs.php');
require_once (dirname(__FILE__).DS.'helper.php');

// Include required css file
if(!defined('JAJOBBOARD_JAJOBSCOUNTER_CSS')){
	 JHTML::stylesheet('mod_jajobs_counter.css', 'modules/mod_jajobs_counter/assets/');	 
	 define('JAJOBBOARD_JAJOBSCOUNTER_CSS', 1);
}

global $jbconfig, $mainframe;
component_configs();
checkPermission('view_list_jobs');

/**
* Require Cache 
* */
require_once(JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'asset'.DS.'jacache'.DS.'jacache.php');
require_once(JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'asset'.DS.'jacache'.DS.'jajob.inc.php');
$cache = new JA_Cache($jbconfig['cache']->get('cache_base', JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'cache'), $jbconfig['cache']->get('cache_time', 5), $jbconfig['cache']->get('caching', true));
$cache_id = md5('mod_jajobs_counter');
$cache_group = 'jajobs';
if($cache->check_cache($cache_id, $cache_group)) 
	return ;
else 
	$oldlen = strlen(ob_get_contents());
/* End Cache */

$model = new JobBoardModelJAJobs();

$field_name		= $params->get( 'field_name', 'job_type' );
$where_more		= " and f.display!='hide_all' AND f.field_type IN ('MSELECT', 'SELECT') AND f.is_on_filter = 1  AND f.field_name = '{$field_name}'";
$this->fieldlist = $model->getEditFieldList( $where_more );

if( !empty($this->fieldlist[0]) )
	$this->all_items = modJAJobsCounter::get_list_jobs($model, '', $this->fieldlist[0], $params);
else $this->all_items = "";

$this->Itemid = modJAJobsCounter::_findItem();

$path = JModuleHelper::getLayoutPath('mod_jajobs_counter', 'default');
if (file_exists($path)) {
	require($path);
}

/* Set Cache */
$maincontent = substr(ob_get_contents(), $oldlen);
if($maincontent){
	$cache->_cache->store($maincontent, $cache_id, $cache_group);		
}

?>